//package fun.formoji.commons.oauth;
//
//import fun.formoji.commons.oauth.model.AuthUser;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.oauth2.provider.OAuth2Authentication;
//
///**
// * <code>OauthContextHolder</code>
// * <desc>
// * 描述：
// * <desc/>
// * <b>Creation Time:</b> 2021/1/19 18:05.
// *
// * @author hshe
// */
//@Slf4j
//public class OauthContextHolder {
//    private OauthContextHolder(){}
//    /**
//     * JwtToken内容解析
//     */
//    public static OauthUser getOauthUser() {
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        OAuth2Authentication oAuth2Auth = (OAuth2Authentication) authentication;
//        authentication = oAuth2Auth.getUserAuthentication();
//        OauthUser oauthUser = null;
//        try {
//            if (authentication instanceof UsernamePasswordAuthenticationToken) {
//                AuthUser principal = (AuthUser) authentication.getPrincipal();
//                oauthUser = new OauthUser();
//                oauthUser.setId(principal.getId());
//                oauthUser.setUsername(principal.getUsername());
//                oauthUser.setPassword(principal.getPassword());
//            }
//        } catch (Exception e) {
//            log.error("Cannot get user info by securityContext , please verify the legitimacy of users access");
//        }
//        return oauthUser;
//    }
//}
